import net.sevensoft.nocrastinate.model.Action

class ActionController {
  def scaffold = Action    
/*
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ actionList: Action.list( params ) ]
    }

    def show = {
        def action = Action.get( params.id )

        if(!action) {
            flash.message = "Action not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ action : action ] }
    }

    def delete = {
        def action = Action.get( params.id )
        if(action) {
            action.delete()
            flash.message = "Action ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "Action not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def action = Action.get( params.id )

        if(!action) {
            flash.message = "Action not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ action : action ]
        }
    }

    def update = {
        def action = Action.get( params.id )
        if(action) {
            action.properties = params
            if(!action.hasErrors() && action.save()) {
                flash.message = "Action ${params.id} updated"
                redirect(action:show,id:action.id)
            }
            else {
                render(view:'edit',model:[action:action])
            }
        }
        else {
            flash.message = "Action not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def action = new Action()
        action.properties = params
        return ['action':action]
    }

    def save = {
        def action = new Action(params)
        if(!action.hasErrors() && action.save()) {
            flash.message = "Action ${action.id} created"
            redirect(action:show,id:action.id)
        }
        else {
            render(view:'create',model:[action:action])
        }
    }
*/
}
